package com.ruoyi.web.controller.system.city;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.IdUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.city.CityApply;
import com.ruoyi.system.service.city.ICityApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合作申请Controller
 * 
 * @author cjq
 * @date 2023-07-24
 */
@RestController
@RequestMapping("/system/city/apply")
public class CityApplyController extends BaseController
{
    @Autowired
    private ICityApplyService cityApplyService;

    /**
     * 查询合作申请列表
     */
    @PreAuthorize("@ss.hasPermi('city:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityApply cityApply)
    {
        startPage();
        List<CityApply> list = cityApplyService.selectCityApplyList(cityApply);
        return getDataTable(list);
    }

    /**
     * 导出合作申请列表
     */
    @PreAuthorize("@ss.hasPermi('city:apply:export')")
    @Log(title = "合作申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityApply cityApply)
    {
        List<CityApply> list = cityApplyService.selectCityApplyList(cityApply);
        ExcelUtil<CityApply> util = new ExcelUtil<CityApply>(CityApply.class);
        util.exportExcel(response, list, "合作申请数据");
    }

    /**
     * 获取合作申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('city:apply:query')")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return success(cityApplyService.selectCityApplyByApplyId(applyId));
    }

    /**
     * 新增合作申请
     */
    @PreAuthorize("@ss.hasPermi('city:apply:add')")
    @Log(title = "合作申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityApply cityApply)
    {
        cityApply.setApplyId(IdUtil.getSnowflakeNextId());
        return toAjax(cityApplyService.insertCityApply(cityApply));
    }

    /**
     * 修改合作申请
     */
    @PreAuthorize("@ss.hasPermi('city:apply:edit')")
    @Log(title = "合作申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityApply cityApply)
    {
        return toAjax(cityApplyService.updateCityApply(cityApply));
    }

    /**
     * 删除合作申请
     */
    @PreAuthorize("@ss.hasPermi('city:apply:remove')")
    @Log(title = "合作申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(cityApplyService.deleteCityApplyByApplyIds(applyIds));
    }
}
